package com.molyfun.parents.activity.course.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.molyfun.parents.R;
import com.molyfun.parents.activity.course.bean.CourseMediaBean;
import com.molyfun.parents.activity.course.view.courseitem.CourseCellFactory;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by william(liuchao.hit@gmail.com).
 * Date:9/19/16.
 * 课程
 */
public class CourseDetailAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

//    private static final int TYPE_HEADER = 1001;
//    private static final int TYPE_CATEGORY = 1002;
    private Context mContext;

    private List<CourseMediaBean> mDataList;

    public CourseDetailAdapter(Context mContext) {
        this.mContext = mContext;
    }

    public void refreshData(List<CourseMediaBean> courseBeanList){
        this.mDataList = courseBeanList;
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new CourseDetailCellViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_course_detail_cell,parent,false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        CourseDetailCellViewHolder courseViewHolder = (CourseDetailCellViewHolder) holder;
        courseViewHolder.mCourseDesc.setText(mDataList.get(position).getGalleryname());
        courseViewHolder.mCourseItem.removeAllViews();
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        courseViewHolder.mCourseItem.addView(CourseCellFactory.getFactory(mContext, mDataList.get(position)), lp);
//        courseViewHolder.mCourseItem.addView();
//        courseViewHolder.mCourseImg

    }


    @Override
    public int getItemCount() {
        if(mDataList == null){
            return 0;
        }
        return mDataList.size();
    }


    class CourseDetailCellViewHolder extends RecyclerView.ViewHolder {

        @InjectView(R.id.course_item)
        LinearLayout mCourseItem;
        @InjectView(R.id.course_item_desc)
        TextView mCourseDesc;

        public CourseDetailCellViewHolder(View view) {
            super(view);
            ButterKnife.inject(this, view);
        }
    }

}
